const Koa = require('koa');
const server = new Koa();
const views = require('koa-views');
const path = require('path');
const static = require('koa-static');
const bodyParse = require('koa-bodyparser'); //处理post请求

const routes = require('./rootes');

// 模板引擎
server.use(views(path.join(__dirname, './templates'), {
   extension: 'ejs'
}))

// 静态资源入口
server.use(static(
    path.join(__dirname, './static')
))

// 中间件、路由等
server.use(bodyParse())
      .use(routes.routes())
      .use(routes.allowedMethods())


server.listen(8000, () => {
    console.log('server run in 127.0.0.1:8000')
})